package com.wanmait.shoppingsys.util;

import java.util.ArrayList;
import java.util.List;


import com.wanmait.shoppingsys.vo.Specialty;



public class GoodsShopCar {
	private List<Specialty> specialtys = new ArrayList<Specialty>();
	public int addCount(Integer id,int count) {
		for(Specialty b:specialtys) {
			if(b.getId().equals(id)) {
				//购物车里有这本书
				b.setCount(b.getCount()+count);
				if(b.getCount()<0)b.setCount(0);
				return b.getCount();
			}
		}
		return 0;
	}
	public Double getTotalPrice() {
		double total = 0.0;
		for(Specialty b:specialtys) {
			total+= b.getPrice()*b.getCount();
		}
		return total;
	}
	public void addSpecialty(Specialty specialty) {
		boolean find = false;
		for(Specialty b:specialtys) {
			if(b.getId().equals(specialty.getId())) {
				//购物车里有这本书
				b.setCount(b.getCount()+specialty.getCount());
				find = true;
				break;
			}
		}
		//没有找到就添加到购物车
		if(!find) {
			specialtys.add(specialty);
		}
	}
	
	public List<Specialty> getSpecialtys(){
		return specialtys;
	}
}
